/**
 * Copyright (c) 2019-2021,  陈俊兵 (cjb6b.com@gmail.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ktjiaoyu.advance.refs;

import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;

/**
 * 软引用测试
 * @packageName com.ktjiaoyu.advance.refs
 * @fileName SoftRefTest.java
 * @author 陈俊兵 (cjb6b.com@gmail.com)
 * @createTime 2023/7/27 14:53
 * @lastModify 2023/7/27 14:53
 * @version 1.0.0
 */
public class SoftRefTest {

    // 设置VM参数，测试软引用
    // -Xms5M -Xmx6M
    public static List<SoftReference<byte[]>> list = new ArrayList();

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            byte[] bytes = new byte[1024 * 1024];
            SoftReference<byte[]> softRef = new SoftReference<>(bytes);
            list.add(softRef);
        }
        // 通知gc
        System.gc();
        for (SoftReference<byte[]> softRef : list) {
            System.out.println(softRef.get());
        }
    }
}
